import React, { Component } from "react"
import StudentsAdd from "./StudentsAdd"
import StudentsUpdate from "./StudentsUpdate"
import StudentsList from "./StudentsList"
// import StudentsSearch from "./StudentsSearch"
import axios from "axios"
export default class Students extends Component {

    constructor(){
        super();
        this.state = {
            student:{},
            students:[],
            pagination:{},
            updateVisible:false,
            type:"",
            value:""
        }
    }
    componentWillMount(){
        this.show();
    }
    show = (page = 1,rows = 5,type,value) => {
  
        axios({
            method:"get",
            url:"/students",
            params:{
                page,rows,type,value
            }
        }).then(({data}) => {
            this.setState({
                students:data.rows,
                pagination:{
                    current:data.curpage,
                    pageSize:data.eachpage,
                    total:data.total,
                    
                },
                type,value
            })
        })
    }
    openUpdate = (student) => {
        this.setState({
            student,
            updateVisible:true
        })
    }
    closeUpdate = () => {
        this.setState({
            updateVisible:false
        })
    }
    render() {
        return <div >
            <StudentsAdd show={this.show}></StudentsAdd>
            {/* <StudentsSearch show={this.show}></StudentsSearch>
             */}
             <StudentsUpdate show={this.show} closeUpdate={this.closeUpdate} visible={this.state.updateVisible}  students={this.state.students}></StudentsUpdate>
            <StudentsList openUpdate={this.openUpdate} show={this.show} students={this.state.students} pagination={this.state.pagination}></StudentsList>

        </div>;
    }
}
